package com.sl.binarytree;

import java.util.Stack;

/**
 * Created by lisulong on 2019/4/1.
 * 深度遍历
 */
public class DepthFirstSearch {
    public void depthTraversal(ListNode node) {
        if (node == null) {
            System.out.print("empty tree");
            return;
        }
        Stack<ListNode> stack = new Stack<ListNode>();
        stack.push(node);
        while (!stack.isEmpty()) {
            ListNode rnode = stack.pop();
            System.out.print(rnode.strVal + "  ");
            if (rnode.right != null) {
                stack.push(rnode.right);
            }
            if (rnode.left != null) {
                stack.push(rnode.left);
            }
        }
    }
}
